﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using SP.SPProjects.WebParts.Support;
using Microsoft.SharePoint.Linq;

namespace SP.SPProjects.WebParts.Model
{
    public partial class DataContext : Microsoft.SharePoint.Linq.DataContext
    {
        public DataContext() :base(SPContext.Current.Web.Url)
        {
            this.OnCreated();
        }
    }

    public partial class BaseTask : Task
    {
        public string TaskStatusColor
        {
            get 
            {
                if (this.TaskStatus.Value == Model.TaskStatus.Completed)
                    return Constants.IMAGE_STATUS_COMPLETED;
                if (!this.DueDate.HasValue)
                    return null;

                int daysAfterDue = DueDate.Value.Date.Subtract(DateTime.Today).Days;
                
                if (daysAfterDue >= Constants.DUE_DAY_FOR_GREEN)
                    return Constants.IMAGE_STATUS_GREEN;
                else if (daysAfterDue >= Constants.DUE_DAY_FOR_ORANGE)
                    return Constants.IMAGE_STATUS_ORANGE;
                else
                    return Constants.IMAGE_STATUS_RED;
            }
        }
    }

}
